# encoding: utf-8
from flask import Flask
from flask import render_template
import mod_health_care_guide
import mod_medical_info
import mod_health_check
import mod_video
import mod_hire
import mod_health_article
import mod_tender
import mod_column
import mod_doctor
import mod_department
import mod_news
import mod_special
import mod_home
import mod_honor
from flask import request

app = Flask(__name__)


@app.route("/")
def on_home():
    banner_list = mod_home.get_banner_list()
    doctor_list = mod_doctor.get_list()
    hopspital_news_list = mod_news.get_collection(2)  # 院内新闻
    break_news_list = mod_news.get_collection(1)  # 重大新闻
    break_news_list.reverse()
    break_news_list2 = break_news_list[0:6]
    departments = mod_department.get_list()
    index_1_departments = []
    index_2_departments = []
    for department in departments:
        index = department["index"]
        if index == 1:
            index_1_departments.append(department)
        elif index == 2:
            index_2_departments.append(department)
    return render_template('home.html', banner_list=banner_list, doctors=doctor_list,
                           departments1=index_1_departments, departments2=index_2_departments,
                           hopspital_news_list=hopspital_news_list, break_news_list=break_news_list2)


@app.route("/news_collection")
def on_news_collection():
    news_type = int(request.args.get('type'))
    docs = mod_news.get_collection(news_type)
    docs.reverse()
    # title = '重大新闻'
    # if news_type == 2:
    #     title = 'u院内新闻'
    # elif news_type == 3:
    #     title = '医院公告'
    # elif news_type == 4:
    #     title = '医院院报'
    # elif news_type == 5:
    #     title = '对外合作'
    # return render_template('news_collection.html', news_list=docs, title=title)
    return render_template('news_collection.html', news_list=docs)


@app.route("/news")
def on_news():
    info_id = int(request.args.get('id'))
    doc = mod_news.get_detail(info_id)
    return render_template('news.html', news=doc)


# 医生详情
@app.route("/doctor")
def on_doctor():
    info_id = int(request.args.get('id'))
    doc = mod_doctor.get_detail(info_id)
    return render_template('doctor.html', doctor=doc)


@app.route("/department")
def on_department():
    info_id = int(request.args.get('id'))
    doc = mod_department.get_detail(info_id)
    doctor_lists = mod_doctor.get_list_by_department_name(doc['name'])
    return render_template('department.html', department=doc, doctors=doctor_lists)


@app.route("/introduce")
def on_introduce():
    return render_template('introduce.html')


@app.route("/introduce_admin")
def on_introduce_admin():
    return render_template('introduce_admin.html')


@app.route("/introduce_architect")
def on_introduce_architect():
    return render_template('introduce_architect.html')


@app.route("/leader")
def on_leader():
    return render_template('leader.html')


@app.route("/introduce_set")
def on_introduce_set():
    return render_template('introduce_set.html')


@app.route("/introduce_culture")
def on_introduce_culture():
    return render_template('introduce_culture.html')


@app.route("/introduce_honor")
def on_introduce_honor():
    honor_list = mod_honor.get_banner_list()
    return render_template('introduce_honor.html', honor_list=honor_list)


@app.route("/news_set")
def on_news_set():
    news_2_list = mod_news.get_collection(2)  # 院内新闻
    news_1_list = mod_news.get_collection(1)  # 重大新闻
    news_3_list = mod_news.get_collection(3)  # 医院公告
    news_2_list.reverse()
    news_1_list.reverse()
    news_3_list.reverse()
    return render_template('news_set.html', news_2_list=news_2_list[0:6], news_1_list=news_1_list,
                           news_3_list=news_3_list[0:6])


@app.route("/service_set")
def on_service_set():
    medic_infos = mod_medical_info.get_list()
    medic_infos1 = medic_infos[0:4]
    special_list = mod_special.get_list()
    return render_template('service_set.html', medic_infos=medic_infos1, special_list=special_list)


@app.route("/doctor_set")
def on_doctor_set():
    department = request.args.get('department', 'all')
    title = request.args.get('title', 'all')
    is_query_department = (not department == 'all')
    is_query_title = (not title == 'all')
    if is_query_department:
        res_list = mod_doctor.get_list_by_department_name(department)
        return render_template('doctor_set.html', doctors=res_list)
    elif is_query_title:
        res_list = mod_doctor.get_list_by_title(title)
        return render_template('doctor_set.html', doctors=res_list)
    else:
        res_list = mod_doctor.get_list()
        return render_template('doctor_set.html', doctors=res_list)


@app.route("/deparment_set")
def on_deparment_set():
    departments = mod_department.get_list()
    index_1_departments = []
    index_2_departments = []
    for department in departments:
        index = department["index"]
        if index == 1:
            index_1_departments.append(department)
        elif index == 2:
            index_2_departments.append(department)
    return render_template('department_set.html', departments1=index_1_departments,
                           departments2=index_2_departments)


@app.route("/hire_set")
def on_hire_set():
    hire_list = mod_hire.get_list()
    tender_list = mod_tender.get_list()
    hire_list.reverse()
    tender_list.reverse()
    return render_template('hire_set.html', tenders=tender_list, hires=hire_list)


# column详情集合页
@app.route("/column")
def on_column():
    column_list = mod_column.get_list()
    return render_template('column.html', columns=column_list)


# 专栏文章详情
@app.route("/column_detail")
def on_column_detail():
    info_id = int(request.args.get('id'))
    content = mod_column.get_detail(info_id)
    if content is None:
        return render_template('column_detail.html', content="error id")
    else:
        return render_template('column_detail.html', content=content)


# 根据column_id查询这个专题下面的文章列表
@app.route("/column_list")
def on_column_list():
    column_id = int(request.args.get('id'))
    column_list = mod_column.get_column_list(column_id)
    column = mod_column.get_column_info(column_id)
    return render_template('column_list.html', title=column["name"], columns=column_list)


@app.route("/health_set")
def on_health_set():
    articles_list = mod_health_article.get_list()
    video_list = mod_video.get_list()
    articles_list.reverse()
    return render_template('health_set.html', articles=articles_list, videos=video_list)


# 健康视频
@app.route("/health_video")
def on_health_video():
    info_id = int(request.args.get('id'))
    doc = mod_video.get_detail(info_id)
    if doc is None:
        return render_template('health_video.html', content="error id")
    else:
        return render_template('health_video.html', video=doc)


# 健康文章
@app.route("/health_article_detail")
def on_health_article_detail():
    info_id = int(request.args.get('id'))
    doc = mod_health_article.get_detail(info_id)
    if doc is None:
        return render_template('health_article_detail.html', content={"title": "error id", "detail": ""})
    else:
        return render_template('health_article_detail.html', content=doc)


@app.route("/health_article_detail_list")
def on_health_article_detail_list():
    return render_template('health_article_detail_list.html')


@app.route("/mobile_set")
def on_mobile_set():
    return render_template('mobile_set.html')


@app.route("/service_time")
def on_service_time():
    return render_template('service_time.html')


@app.route("/service_pre")
def on_service_pre():
    return render_template('service_pre.html')


@app.route("/location")
def on_location():
    return render_template('location.html')


@app.route("/test")
def on_test():
    info_id = int(request.args.get('id'))
    detail = mod_medical_info.get_detail(info_id)
    if detail is None:
        return render_template('test.html', content="error id")
    else:
        return render_template('test.html', content=detail)


# 就诊须知详情
@app.route("/medical_info_detail")
def on_medical_info():
    info_id = int(request.args.get('id'))
    doc = mod_medical_info.get_detail(info_id)
    if doc is None:
        return render_template('medical_info_detail.html', content="error id")
    else:
        return render_template('medical_info_detail.html', content=doc)


# 就诊须知列表
@app.route("/medical_info_list")
def on_medical_info_list():
    infos = mod_medical_info.get_list()
    return render_template('medical_info_list.html', infos=infos)


# 医保指南详情
@app.route("/health_care_guide_detail")
def on_health_care_guide_detail():
    info_id = int(request.args.get('id'))
    detail = mod_health_care_guide.get_detail(info_id)
    if detail is None:
        return render_template('health_care_guide_detail.html', content="error id")
    else:
        return render_template('health_care_guide_detail.html', content=detail)


# 医保指南list
@app.route("/health_care_guide_list")
def on_health_care_guide_list():
    guide_list = mod_health_care_guide.get_list()
    return render_template('health_care_guide_list.html', list=guide_list)


# 体检list
@app.route("/health_check_list")
def on_health_check_list():
    res_list = mod_health_check.get_list()
    return render_template('health_check_list.html', checks=res_list)


# 体检detail
@app.route("/health_check_detail")
def on_health_check_detail():
    info_id = int(request.args.get('id'))
    detail = mod_health_check.get_detail(info_id)
    if detail is None:
        return render_template('health_check_detail.html', content="error id")
    else:
        return render_template('health_check_detail.html', content=detail)


# 招聘详情
@app.route("/hire_detail")
def on_hire_detail():
    info_id = int(request.args.get('id'))
    detail = mod_hire.get_detail(info_id)
    if detail is None:
        return render_template('hire_detail.html', content="error id")
    else:
        return render_template('hire_detail.html', content=detail)


# 招标详情
@app.route("/tender_detail")
def on_tender():
    info_id = int(request.args.get('id'))
    detail = mod_tender.get_detail(info_id)
    if detail is None:
        return render_template('tender_detail.html', content="error id")
    else:
        return render_template('tender_detail.html', content=detail)


# 特色专科列表
@app.route("/special_list")
def on_special_list():
    special_list = mod_special.get_list()
    return render_template('special_list.html', list=special_list)


# 特色专科详情
@app.route("/special_detail")
def on_special_detail():
    info_id = int(request.args.get('id'))
    doc = mod_special.get_detail(info_id)
    return render_template('special_detail.html', speical=doc)


# 特色专科详情
@app.route("/report_list")
def on_report_list():
    return render_template('report_list.html')


if __name__ == "__main__":
    app.run(debug=True)
